package com.tonghe.service.role;

import com.tonghe.dao.BaseDao;
import com.tonghe.dao.role.RoleDao;
import com.tonghe.dao.role.RoleDaoImpl;
import com.tonghe.pojo.Role;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @Date:2021/12/6- 12- 06- 22:34
 **/
public class RoleServiceImpl implements RoleService {

    //引入dao
    private RoleDao roleDao;
    public RoleServiceImpl(){
        roleDao = new RoleDaoImpl();
    }//构造赋值

    //查询用户列表
    @Override
    public List<Role> getRoleList() {
        Connection connection = null;
        List<Role> roleList= null;
        try {
            connection =BaseDao.getConnection();
            roleList = roleDao.getRoleList(connection);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            BaseDao.closeResource(connection,null,null);
        }
        return roleList;
    }

    @Test
    public void test(){
        RoleServiceImpl roleService = new RoleServiceImpl();
        List<Role> roleList = roleService.getRoleList();
        for (Role role:roleList ) {
            System.out.println(role.getRoleName());
        }
    }
}
